<template>
    <div class="view_con">
        <div class="email_con">
            <div class="email_left">
                <div class="email_btn">
                    <img src="/static/images/edit.png" alt="">
                    <span>留言</span>
                </div>
            </div>
            <div class="email_right">
                <textarea name="" id="" cols="30" rows="10" placeholder="输入正文" v-model="con"></textarea>
                <div class="submit_btn" @click="submit">提交</div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            con:'',
            type:1,
            token:''
        };
    },

    mounted() {
        let token = localStorage.getItem('token')
        if(!token){
            this.$router.push({
                path:'/prevlogin'
            })
        }else{
            this.token = token
        }
    },
    watch:{
        $route:{
            handler(newval,oldval){
                this.type = newval.query.type
            },
            deep:true,
            immediate:true
        }
    },
    methods: {
        submit(){
            if(!this.con){
                alert('请完善信息后提交')
            }else{
                let params = {
                    title:'书记信箱',
                    content:this.con,
                    belong:this.type
                }
                this.$api.post('addMessage',params,{
                    headers:{
                        Authorization:this.token
                    }
                }).then(res=>{
                    if(res.code===200){
                        alert(res.data.msg)
                        this.con = ''
                    }else{
                        alert(res.message)
                    }
                })
            }
            
        }
    },
};
</script>

<style lang="scss" scoped>
   @import  '@/assets/css/common.scss';
</style>